/**
 * Created by chaoCheng on 2017/1/12.
 */
function PlayPlanController(
    initialList,//路由中预加载数据的注入
    Stream,
    Sorter,
    Demo,
    PlayPlan,
    $uibModal,
    $log,
    $scope,
    $state,
    $stateParams
) {
    var vm = this

    initialList.$promise.then(function(response) {
        // 将后台返回的数据填充
        console.info(response)
        vm.playplans=response.content

        // 是否显示分页
        vm.isLoaded = true;
        vm.queryParams = _.clone($stateParams)
        vm.totalItems = response.totalElements
        vm.totalPages = response.totalPages
    })


    // 点击delete事件调用该函数
    vm.delete = function(playplan) {
        // 模拟窗口打开之后执行该函数
        var modalInstance = $uibModal.open({
            animation: $scope.animationsEnabled,
            templateUrl: 'deletePlayPlanContent.html',
            controller: 'PlayPlanInstanceCtrl',
            size: playplan
        });

        // 模拟窗口关闭后回传调用
        modalInstance.result.then(function (selectedItem) {
            if(selectedItem == 'ok') {
                PlayPlan.delete({
                    id : playplan.id
                }).$promise.then(function(){
                    $state.reload($state.current)
                })
            }
        });
    }

    // 去除查询条件
    vm.reset = function(parameter) { vm.queryParams = {}; }

    // 查询调用
    vm.search = function() {
        $state.go($state.current, vm.queryParams)
    }

    vm.add = function() {
        $state.go('playPlanAdd' , vm.queryParams)
    }
    vm.update=function(playPlan){
        $state.go('playPlanUpdate' , {'planId':playPlan.id,'planName':playPlan.planName})
    }
    vm.detail=function(playplan){
        $state.go('detail' , {'planId':playplan.id,'planName':playplan.planName})
    }

}


